<!---
Name:        products.cfm
Author:      Dmitry Svito (prostotelo@gmail.com)
Description: products summary
Created:     26.03.2011
--->

<cfparam name="Form.x" type="string" default="">
<cfparam name="Categ" type="integer" default="0">
<cfparam name="del" type="integer" default="0">
<cfparam name="Pr" type="integer" default="0">

<cfif IsDefined("URL.cat")>
	<cfset Categ = "#URL.cat#">
<cfelse>
	<cflocation url="categories.cfm">
</cfif>

<!---Categories--->
<cfset CatObjDAO = createObject("component", "Catalog.DataAccessLayer.CategoriesDAO").init() />
<cfset CategoryRow = CatObjDAO.read(Categ)>

<!---Products--->
<cfset ProdObjGate	= createObject("component", "Catalog.DataAccessLayer.ProductsGateway").init() />
<cfset ProductsOfCat = ProdObjGate.getprodofcat(Categ)>

<html>
<head>
	<title>
		Joe's Catalog
		Products
	</title>
</head>
<body>
<a href="categories.cfm">Back to Categories</a>
<table width="25%" border="0" cellspacing="2" cellpadding="2" summary="Categories">
    <caption align="top">
        <strong><cfoutput>#CategoryRow.getCategoryName()#</cfoutput> Products</strong>
    </caption>
<cfoutput>
<cfform name="ProdForm">
<cfloop array="#ProductsOfCat#" index="Product">
	<cfset ProductID = Product.getProductID()>
    <tr>
        <td width="90%">
			#Product.getName()#
        </td>
        <td>
        	<a href="addeditprod.cfm?prod=#ProductID#&cat=#Categ#" target="_self">
        		<img src="/catalog/images/pencil.jpg" alt="" width="16" height="16" title="Edit"/>
			</a>
        </td>
        <td>
			<cfinput type="image" name="x" src="/catalog/images/x.jpg" width="16" height="16" value="#ProductID#">
        </td>
    </tr>
</cfloop>
</cfform>
</cfoutput>
	<tr>
		<td colspan="4" align="center">
			<cfform name="prodform" action="addeditprod.cfm?add=1&cat=#Categ#" method="post" accept-charset="utf-8">
				<cfinput type="submit" name="operation" value="Add">
			</cfform>
		</td>
	</tr>
</table>
<cfif isDefined("client.delmes")>
	<cfset delornot = "#client.delmes#">
	<cfif delornot IS "true">
		<cfoutput>
			Product deleted.
		</cfoutput>
	</cfif>
	<cfset client.delmes = "false">
</cfif>
<cfif Form.x IS NOT "">
	<cfset client.CatID = "#Categ#">
	<cfset client.ProdID = "#Form.x#">
	<cflocation url="delete.cfm?flag=p">
</cfif>
</body>
</html>